<template>
	<view class="content">
		<view class="userInfo">
			<view class="Info" style="height:140rpx;display: flex;flex-direction: row;">
				<view class="icon">
					<image :src="prizeinner.avatar" alt="" style="height: 140rpx;margin: 0 40rpx;" mode="heightFix">
				</view>
				<view>
					<view style="color: #fff;font-weight: bold;padding: 10rpx 0;font-size: 36rpx;">{{prizeinner.name}}
					</view>
					<view style="color: #fff;font-weight: bold;padding: 10rpx 0;">
						{{prizeinner.mobile}}
					</view>
				</view>
			</view>
		</view>
		<view class="prize">
			<view class="lt">
				<img :src="prizeinner.prizesImage" alt="">
			</view>
			<view class="rt">
				<view>奖品名称：<text>{{prizeinner.prizesName}}</text></view>
				<view>奖品数量：<text>{{prizeinner.prizesSum}}</text></view>
			</view>
			<button open-type="share">
				邀请好友抽奖
			</button>
		</view>
		<view class="other">发布时间：<text style=" color: red;">{{prizeinner.createTime}}</text></view>
		<view class="other">
			<view>奖品介绍：</view>
			<view style=" color: red; font-size: 36rpx;">{{prizeinner.prizesDescription}}</view>
		</view>

		<view class="app">
			<label class="dot" @click="addPrize">参与抽奖</label>
		</view>

		<swiper class="ad" autoplay="true" interval="3000" circular="true" :style="{'height':'400rpx' }"
			@change="swiper2Change">
			<swiper-item class="ad-item" v-if="bannerAdShow">
				<ad unit-id="adunit-32ee9f1ef2bea9fa" @error="offAd" @close="offAd"></ad>
			</swiper-item>
			<swiper-item class="ad-item" v-for="(item, index) in adList" :key="index" @click="goSwiperDetail(item)"
				v-if="item.status==0">
				<!--        <view class="ad-item" v-for="(item, index) in adList" :key="index" @click="goAd(item)">-->
				<image class="ad-img" @load="loadImage($event,item)" :style="{'height':imgheight+'rpx' }" v-if="item"
					:src="item.img"></image>
				<!--        </view>-->
			</swiper-item>
		</swiper>



		<view class="tips" style="display: flex;align-items: center;color:red;margin: 30rpx auto;">
			<text @click="showTips">免责声明</text> <text style="padding: 0 20rpx;">|</text> <text
				@click="complaint">我要投诉</text>
		</view>
	</view>
</template>

<script>
	import share from '@/mixins/share.js'
	export default {
		data() {
			return {
				prizeinner: {},
				prizeId: '',
				swiper2Index: 0,
				bannerAd: true,
				adList: []
			}
		},
		onShareAppMessage() {
			let data = {
				title: '我真在参与该抽奖，邀请你一起来抽奖吧',
				path: "/myPage/prize_com/components/addDetial?prizeId=" + this.prizeId + "&shareUserId=" + uni
					.getStorageSync('userId')
			}
			return data
		},
		onLoad(options) {
			this.prizeId = options.prizeId
			this.api_get(options.prizeId)
			if (options.shareUserId) {
				this.shareUserId = options.shareUserId
			}
			this.getTv()
		},
		methods: {
			api_get(id) {
				this.$api.request({
					url: this.$api.getprizeDetial + `/${id}`
				}).then((res) => {
					if (res.code == 200) {
						console.log(res.data.apiHtPrizes);
						this.prizeinner = res.data.apiHtPrizes
					}
				})
			},
			addPrize() {
				let userId = uni.getStorageSync('userId')
				let longitude, latitude
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						longitude = res.longitude
						latitude = res.latitude
					}
				});
				uni.showModal({
					title: "提示",
					content: "是否参与本次抽奖？",
					success: (res) => {
						if (res.confirm) {
							let params = {
								prizesId: this.prizeId,
								userId: userId,
								isCheck: 0,
								longitude: longitude,
								latitude: latitude,
							};
							if (this.shareUserId) {
								params.inviter = this.shareUserId;
							}
							this.$api.request({
								url: this.$api.addprize,
								method: 'POST',
								data: params
							}).then((res) => {
								console.log(res);
							})

						}
					},
					fail: () => {
						return
					}
				})
			},
			showTips() {
				uni.showModal({
					title: '免责声明',
					content: '我们仅提供发起及参与抽奖的平台，不对第三方发起人行为承担责任，所有抽奖奖品均由发起者提供并发放;本平台会在法律范围内尽可能地规范、督促用户遵守相关法律和平台使用规则，营造一个良好的公平的抽奖平台给用户',
					confirmText: '我知道了',
					showCancel: false,
				})
			},
			complaint() {
				uni.navigateTo({
					url: '/pages/my/service/service'
				})
			},
			getTv() {
				this.$api.request({
					url: this.$api.getBanner + "?location=" + 1,
				}).then(res => {
					console.log(res, '广告请求');
					this.adList = res.data;
				})
			},
			loadImage(event, item) {
				this.imgwidth = event.detail.width, //获取图片真实宽度
					this.imgheight = event.detail.height
				let ratio = event.detail.width / event.detail.height
				let viewHeight = 750 / ratio
				this.imgHeights.push(viewHeight)
			},
			swiper2Change(e) {
				this.swiper2Index = e.detail.current
			},
			offAd() {
				this.bannerAd = false
			},
		}
	}
</script>

<style scoped>
	.content {
		width: 100%;
		display: flex;
		flex-direction: column;
		background-color: #ddd;
		position: relative;
	}

	.prize {
		display: flex;
		flex-direction: column;
		width: 700rpx;
		height: 600rpx;
		margin: 0 auto;
		margin-top: 20rpx;
		background: linear-gradient(to right, red, orange 50%, yellow);
		border-radius: 30rpx;
		position: relative;
	}

	.prize button {
		position: absolute;
		right: 20rpx;
		bottom: 60rpx;
		border-radius: 100rpx;
		border: 1rpx solid red;
	}

	.lt {
		width: 650rpx;
		height: 400rpx;
		margin: 25rpx;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.lt img {
		width: 100%;
		height: 100%;
	}

	.rt {
		width: 100%;
		height: 200rpx;
		margin-top: 25rpx;
		display: flex;
		flex-direction: column;
	}

	.rt view {
		height: 60rpx;
		line-height: 60rpx;
		padding: 30rpx;
		border-radius: 30rpx;
		font-weight: bold;
		/* background-color: #fff; */
	}

	.other {
		width: 700rpx;
		height: 100rpx;
		font-size: 40rpx;
		padding-left: 20rpx;
		line-height: 100rpx;
		background-color: #F5F5DC;
		margin: 20rpx auto;
		border-radius: 30rpx;
	}

	.app {
		position: relative;
		width: 250rpx;
		height: 250rpx;
		margin-left: 250rpx;
		margin-top: 150rpx;
		overflow: hidden;
		border-radius: 125rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.dot {
		width: 200rpx;
		height: 200rpx;
		text-align: center;
		line-height: 200rpx;
		font-weight: bold;
		font-size: 38rpx;
		color: #fff;
		display: block;
		position: relative;
		border-radius: 50%;
		background-color: red;
		z-index: 1;
	}

	.dot::after {
		width: 100%;
		height: 100%;
		content: "";
		border-radius: 50%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -2;
		background-color: blue;
		animation: dot-play 4s linear 400ms infinite;
	}

	.dot::before {
		width: 100%;
		height: 100%;
		content: "";
		border-radius: 50%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
		background-color: red;
		animation: dot-play 4s linear 200ms infinite;
		animation-delay: 2s;
		/* 延迟 2s */
	}

	@keyframes dot-play {
		from {
			transform: scale(1);
			opacity: .2;
		}

		to {
			transform: scale(4);
			opacity: 0;
		}
	}

	.ad {
		width: 710rpx;
		display: flex;
		position: relative;
		margin-top: 20rpx;
		height: 0;

	}


	.ad-item {
		width: 100%;
		height: 100%;
		border-radius: 15rpx;

	}

	.ad-img {
		height: 100% !important;
		width: 100%;
		border-radius: 15rpx;
	}
</style>